<style>
    .ivu-table td.demo-table-info-column{
        font-size: 18px;
    }
</style>
<template>
    <iview-table
            ref="table"
            :showTable="true"
            :baseURL="queryModel.baseURL"
            :menuId="dataModel.menuId"
            :columns="dataModel.columns"
            :order="dataModel.order"
            :pageNumber="pageModel.pageNumber"
            :pageSize="pageModel.pageSize"
            :defaultFilters="queryModel.defaultFilters"
            v-on="{changeTotalSize:changeTotalSize,changeSelect:changeSelect}">
    </iview-table>
</template>

<script>
    import iviewTable from '@/view/common/table/Table.vue';
    import iviewPage from '@/view/common/page/Page.vue';
    export default {
        components: {
            iviewTable,
            iviewPage
        },
        props: {
            homeId: {
                type: Number,
                default: -1
            }
        },
        data () {
            return {
                baseURL: '/user/home/discount/product',
                selectRows: [],
                queryModel: {
                    // 网关代理路径(必须)+资源路径(可选)
                    baseURL: '/user/home/discount/product',
                    defaultFilters: [
                        {'field': 'home_id', 'value1': -1, 'operate': '=='},
                        {'field': 'discount', 'value1': 0, 'operate': '>'}
                    ]
                },
                dataModel: {
                    menuId: -1,
                    columns: [
                        {
                            title: '品类名称',
                            key: 'categoryName'
                        },{
                            title: '折扣',
                            key: 'discount',
                            render: (h, params) => {
                                let temp = params.row.discount + '折'
                                return h('span', temp)
                            }
                        },
                        {
                            title: '操作',
                            width: 150,
                            align: 'center',
                            render: (h, params) => {
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'primary',
                                            size: 'default'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.select(params.row)
                                            }
                                        }
                                    }, '选择')
                                ]);
                            }
                        }
                    ],
                    order: 'id desc'
                },
                pageModel: {
                    totalSize: 0,
                    pageNumber: 1,
                    pageSize: 10,
                    pageSizeOpts: [10, 50, 100, 500]
                },
                showModal: false,
                status: false
            };
        },
        methods: {
            select (row) {
                this.$emit('selectDiscountProduct', row)
            },
            refresh () {
                this.$refs.table.refresh()
            },
            changeSelect (rows) {
                this.selectRows = rows
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            },
            changePageNumber (pageNumber) {
                this.pageModel.pageNumber = pageNumber
            },
            changePageSize (pageSize) {
                this.pageModel.pageSize = pageSize
            },
            init () {
                this.refresh()
            }
        },
        mounted () {
        },
        watch: {
            homeId: function (val, oldVal) {
                this.queryModel.defaultFilters[0] = {'field': 'home_id', 'value1': val, 'operate': '=='}
                this.refresh()
            }
        }
    }
</script>

<style>

</style>
